﻿using System.Web.SessionState;

namespace System.Modules.Extensions
{
    /// <summary>
    /// HttpSessionStateExtensions
    /// </summary>
    public static class HttpSessionStateExtensions
    {
        /// <summary>
        /// This method return saved object in the session with casting.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="name"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Load<T> (this HttpSessionState session, string name)
        {
            var value = session[name];
            return value == null ? default(T) : (T) value;
        }
    }
}
